import { $wAxios } from '~/utils/api'

class MyUploadAdapter {
  constructor (loader) {
    // The file loader instance to use during the upload.
    this.loader = loader
  }

  // 启动上传
  upload () {
    return new Promise((resolve) => {
      this.loader.file.then((file) => {
        $wAxios.$upOssWithFile(file, process.env.OSS_IMAGE_PREFIX).then((src) => {
          resolve({
            default: src
          })
        })
      })
    })
  }

  // Aborts the upload process.
  abort() {
    // Reject the promise returned from the upload() method.
    // server.abortUpload();
  }
}

function MyCustomUploadAdapterPlugin (editor) {
  editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
    // Configure the URL to the upload script in your back-end here!
    return new MyUploadAdapter(loader)
  }
}

export default MyCustomUploadAdapterPlugin
